<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/icon.css"/>">
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery-1.6.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.panel.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.datagrid.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.messager.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/ext-for-framework.js.jsp"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/locale/easyui-lang-zh_CN.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/js/common.js"/>"></script>
<script type="text/javascript">
	function initList(listDisplayEId) {
		$('#' + listDisplayEId)
				.datagrid(
						{
							nowrap : false,
							striped : true,
							collapsible : true,
							remoteSort : true,
							notSelectByRow : false,
							/* frozenColumns : [ [ {
								field : 'ids',
								checkbox : true
							} ] ], */
							toolbar : [ {
								id : listDisplayEId + '_btn_add',
								text : '新增',
								iconCls : 'icon-add',
								handler : function() {

									window
											.open(
													"<c:url value='/jsp/openIndexSun.jsp?url=/supplier/preSaveSupperForSup.do'/>",
													"sun",
													"width=1200px,height=600px,status=no,scrollbars=yes");

									$('#' + listDisplayEId).datagrid('reload');
								}
							} ],
							onLoadError : function() {
								$.messager.alert('错误', '获取数据失败，请与管理员联系！',
										'error');
							},
							onClickRow : function(rowIndex) {
								$(".myrad").prop("checked", false);
								$(".myrad").eq(rowIndex).prop("checked", true);
							}
						});

	};
	$(document).ready(function() {
		initList('listDisplay');
	});
	function formatRadio(value, rowData, rowIndex) {
		return value = "<input type='radio' class='myrad'  name='radioRole' />";
	}
	//角色状态展示0：有效；1为失效
	function formatDGStateField(value, row, index, field) {
		if (!field) {
			field = this.field;
		}
		var fields = field.split('.');
		var fieldValue = row;
		for (var i = 0; i < fields.length; i++) {
			if (fieldValue[fields[i]] == 0) {
				fieldValue = "有效";
			} else if (fieldValue[fields[i]] == 1) {
				fieldValue = "失效";
			}
		}
		return fieldValue;
	}

	function formatSupType(value, row, index, field) {
		return findSupType(row['supplierId']);
	}

	function findSupType(supId) {
		var returnString;
		$.ajax({
			async : false,
			url : "<c:url value='/supplier/findSupType.do'/>" + "?supId="
					+ supId,
			type : "post",
			success : function(data) {
				if (typeof (data) == 'string') {
					data = JSON.parse(data);
				}
				returnString =data.materType;
			}
		});
		return returnString;
	}
</script>
</head>

<body>
	<table id="listDisplay" title="供应商列表" singleSelect=true
		iconCls="icon-list" idField="id"
		url="<c:url value="/supplier/findsupplier.do"/>"
		style="width: 800px; width: 1180px;" loadMsg="请稍候......"
		pagination="true" pageSize="10"
		pageList="[10,20,30,40,50,100,150,200]" sortName="roleId"
		rownumbers="true" sortOrder="asc">
		<thead>
			<tr>
				<th field="radioRole" width="25" align="center"
					formatter="formatRadio"></th>
				<th field="supplierId" width="80" sortable="true">ID</th>
				<th field="companyName" width="120" sortable="true" editor="text">
					供应商公司名</th>
				<th field="province" width="40" sortable="true" editor="text">
					省份</th>
				<th field="city" width="40" sortable="true" editor="text">市</th>
				<th field="street" width="140" sortable="true" editor="text">街</th>
				<th field="phone" width="120" sortable="true" editor="text">
					联系电话</th>
				<th field="mobile" width="120" sortable="true" editor="text">
					手机</th>
				<th field="isActive" width="80" formatter="formatDGStateField"
					sortable="true" editor="text">是否有效</th>
				<th field="insertTime" width="100" sortable="true" editor="datebox">
					注册时间</th>
				<th field="userId" width="100" sortable="true" editor="datebox">
					登陆用户id</th>
				<th field="userName" width="100" sortable="true" editor="datebox">
					登陆用户账号</th>
				<th field="content" width="100" sortable="true" editor="datebox"
					formatter="formatSupType">供货种类</th>

			</tr>
		</thead>
	</table>
</body>
</html>